package com.zhou.util;

import com.amazonaws.services.sqs.AmazonSQSAsync;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * <pre> 
 *    TODO
 *    aws - sqs 工具类  
 *</pre>
 */

@Component("sqsUtil")
public class SQSUtil{

	
    private final QueueMessagingTemplate queueMessagingTemplate;


	@Autowired
    public SQSUtil(AmazonSQSAsync amazonSqs) {
        this.queueMessagingTemplate = new QueueMessagingTemplate(amazonSqs);
    }

    /**
     * <pre> 
     *TODO
     *      发送消息
     *</pre> 
     * @param message void
     */
    public void send(String queueName,String message) {
        this.queueMessagingTemplate.send(queueName, MessageBuilder.withPayload(message).build());
    }

    
   @SuppressWarnings("unchecked")
    public Message<String> receve(String queueName){
       return (Message<String>)this.queueMessagingTemplate.receive(queueName);
   }
}
